package com.zzl.bonds.ticket.controller;

import com.zzl.apidoc.annotation.ApidocController;
import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.bonds.ticket.dto.TickeoperateLogAddDto;
import com.zzl.bonds.ticket.dto.TickeoperateLogUpdateDto;
import com.zzl.bonds.ticket.dto.TicketOperateLogParams;
import com.zzl.bonds.ticket.entity.TicketOperateLogEntity;
import com.zzl.bonds.ticket.service.TicketOperateLogService;
import com.zzl.general.common.apidoc.annotation.ApidocParamsPage;
import com.zzl.general.common.apidoc.annotation.ApidocResultKeyValR;
import com.zzl.general.common.apidoc.annotation.ApidocReturnPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.apidoc.constants.ResultTypeInR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.utils.LogUtils;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 票的操作记录表
 *
 * @author sunpp
 * @date 2022-02-16 11:14:07
 */
@ApidocController("7票的操作记录表")
@RestController
@SuppressWarnings("javadoc")
@RequestMapping("bondsticket/tickeoperatelog")
@Slf4j
public class TicketOperateLogController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired
    private TicketOperateLogService ticketOperateLogService;


    /**
     * 我的票的操作记录
     */
    @PostMapping("/listOperateLog")
    @ApidocOperation(description = "票的操作记录", operationId = "7002")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_ARRAY, key = "list", valueClass = TicketOperateLogEntity.class)
    })
    public Result listOperateLog(@ApidocParam(name = "修改的票的操作记录表对象值", required = true) @RequestBody TicketOperateLogParams params) {
        return Result.ok().put("list", ticketOperateLogService.listOperateLog(params, this.getUser()));
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApidocOperation(description = "分页查询票的操作记录表数据", operationId = "7001")
    @ApidocReturnPage(genericTypeClass = TicketOperateLogEntity.class)
    public Result list(@ApidocParamsPage(name = "params") @RequestParam Map<String, Object> params) {
        PageUtils page = ticketOperateLogService.queryPage(params);
        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApidocOperation(description = "通过id获取票的操作记录表数据", operationId = "7012")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "tickeoperateLog", valueClass = TicketOperateLogEntity.class)
    })
    public Result info(@ApidocParam(name = "票的操作记录表id", required = true) @PathVariable("id") String id) {
        TicketOperateLogEntity tickeoperateLog = ticketOperateLogService.getById(id);
        return Result.ok().put("tickeoperateLog", tickeoperateLog);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
//    @ApidocOperation(description = "保存票的操作记录表", operationId = "7003")
    @ApidocReturnR
    public Result save(@ApidocParam(name = "保存的票的操作记录表对象值", required = true) @RequestBody TickeoperateLogAddDto tickeoperateLog) {
        try {
            ticketOperateLogService.saveTicketOperateLog(tickeoperateLog, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 修改
     */
    @PutMapping("/update")
//    @ApidocOperation(description = "修改票的操作记录表", operationId = "7004")
    @ApidocReturnR
    public Result update(@ApidocParam(name = "修改的票的操作记录表对象值", required = true) @RequestBody TickeoperateLogUpdateDto tickeoperateLog) {
        try {
            ticketOperateLogService.updateTickeoperateLogById(tickeoperateLog, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
//    @ApidocOperation(description = "删除票的操作记录表", operationId = "7005")
    @ApidocReturnR
    public Result delete(@ApidocParam(name = "删除的票的操作记录表对象id集合", required = true) @RequestBody String[] ids) {
        ticketOperateLogService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }


}
